fix(frontend): resolve set-state-in-effect in RouteAnnouncer (#1063 Phase 2)#1069
Merged
ericsocrat merged 1 commit intomainfrom May 1, 2026
Merged
Conversation
…hase 2) Replace useEffect+useRef pattern with React's canonical 'adjusting state during render' pattern (https://react.dev/learn/you-might-not-need-an-effect). When pathname changes, setState is called during render, which React handles specially by scheduling an immediate re-render without committing the discarded one. Compatible with React Compiler — eliminates the react-hooks/set-state-in-effect violation. Initial render produces no announcement because lastPathname is initialised to the current pathname (if-block skipped). All 11 existing tests pass unchanged — they assert behavior, not implementation. Phase 2 progress: 1/19 violations resolved, 18 remaining across 13 files.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📸 PR ScreenshotsCaptured 2 screenshots (1 mobile, 1 desktop) for 1 changed page(s):
📥 Download screenshots from workflow artifacts. Captured by PR Screenshots workflow • 2026-05-01 |
There was a problem hiding this comment.
Pull request overview
Updates RouteAnnouncer to eliminate a react-compiler/set-state-in-effect warning by switching from useEffect + useRef to React’s render-phase “adjust state during render” pattern while preserving the existing screen-reader announcement behavior.
Changes:
- Removes
useEffect/useRef-based first-render gating. - Introduces
lastPathnamestate initialized fromusePathname()and updates announcement during render when the pathname changes.
Bundle Size Report
✅ Bundle size is within acceptable limits. |
This was referenced May 1, 2026
ericsocrat
added a commit
that referenced
this pull request
May 1, 2026
…) (#1077) Phase 2 of #1063 -- resolves 2 of 19 violations (running total: 12/19 across 9 PRs). Two react-hooks/set-state-in-effect warnings in SearchAutocomplete.tsx resolved by adjusting state during render: 1. Refresh recent-searches list on dropdown open: replaced the show-dep useEffect with a prevShow render-phase tracker. Added a lazy initial-state initializer so the list is hydrated on mount when show is already true (preserves existing test contract). 2. Reset activeIndex when suggestions/query change: replaced the multi-dep useEffect with a composite resetKey + prevResetKey render-phase tracker. Pattern: https://react.dev/learn/you-might-not-need-an-effect#adjusting-some-state-when-a-prop-changes Behaviour unchanged. 32/32 vitest pass, eslint and tsc clean. Cross-references: #1067, #1069, #1070, #1071, #1072, #1073, #1074, #1075, #1076. Co-authored-by: ericsocrat <ericsocrat@users.noreply.github.com>
ericsocrat
added a commit
that referenced
this pull request
May 1, 2026
…#1078) Resolves 3 react-hooks/set-state-in-effect violations in src/app/app/search/page.tsx (Phase 2 of #1063): - Mount-load effect: replaced with lazy useState initializers for recentSearches, showAvoided, viewMode (helpers already SSR-safe via globalThis.localStorage guards) - debouncedQuery sync effect: replaced with Pattern A render-phase tracker (composite submitKey of debouncedQuery + filters) - page reset effect: replaced with Pattern A render-phase tracker (composite pageResetKey of submittedQuery + filters) Validated: 54/54 vitest pass, eslint clean, tsc clean. Phase 2 cumulative: 15/19 (final non-deferred multi-violation file). Cross-refs: #1067 (Phase 1), #1069-#1077 (Phase 2 micro-PRs). Co-authored-by: ericsocrat <ericsocrat@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Resolves 1 of 19
react-hooks/set-state-in-effectviolations from #1063 Phase 2.Replaces
useEffect+useRefwith React's canonical adjusting-state-during-render pattern, which the React Compiler accepts.Why this is safe
lastPathnameinitialised to currentpathname, if-block skipped), pathname change triggers announcement.RouteAnnouncer.test.tsxpass — they assert behaviour (aria attributes, announcement text per route), not implementation.Phase 2 progress
RouteAnnouncer.tsxVerification
npx eslint src/components/common/RouteAnnouncer.tsx— cleannpx vitest run src/components/common/RouteAnnouncer.test.tsx— 11/11 passnpx tsc --noEmit— 0 errorsCloses part of #1063.